from pymongo import MongoClient

from Util.SSHForwarderUtil import instance_ssh_server

server = instance_ssh_server("192.168.0.36", 27015)
server.start()
client = MongoClient("127.0.0.1", server.local_bind_port)
# 数据库名admin
mongodb = client.tasks
# 认证用户密码
mongodb.authenticate('tasks', 'admin123456!')


# 根据任务名称模糊查询
def get_task_info_by_name(task_name):
    # 数据集
    tasks_col = mongodb['tasks']
    # taskinfos = list(tasks.find({'taskName': task_name}))
    # taskinfos = tasks.find({'taskName': {"$in": [name for name in task_name.split(",")]}})
    taskinfos = list(tasks_col.find({"taskName": {"$regex": task_name}}))
    return taskinfos


tasks = get_task_info_by_name("1")
for task in tasks:
    print(task['taskName'])
